# import jieba
# # with open('comment.txt','r') as f:
# #     list = jieba.cut(f.read())
# #     print(' '.join(list))
# from wordcloud import WordCloud
# from os import path
# import jieba.analyse as analyse
#
# d = path.dirname(__file__)
#
# text_path = 'comment.txt' #设置要分析的文本路径
# text = open(path.join(d, text_path),encoding='utf-8').read()
# list = jieba.cut(text)
# lst = '/'.join(list)
# comment = set(lst.split('/'))
# print(len(comment))
import path
import matplotlib.pyplot as plt
from wordcloud import WordCloud
import jieba
from PIL import Image
from scipy.misc import imread
import numpy as np

text_from_file_with_apath = open('comment.txt',encoding='utf-8').read()

wordlist_after_jieba = jieba.cut(text_from_file_with_apath, cut_all=True)
wl_space_split = " ".join(wordlist_after_jieba)
image_loc = np.array(Image.open('mod.png'))
my_wordcloud = WordCloud(font_path='simkai.ttf',width=1500,height=1500,mask=image_loc).generate(wl_space_split)
my_wordcloud.to_file('woed.jpg')
plt.imshow(my_wordcloud,interpolation="bilinear")
plt.axis("off")
plt.show()